<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../jquery2.1.1.min.js"></script>
    <style>
        .b {
            background-color: red
        }

        .a {
            background-color: blue
        }
    </style>
</head>
<body>

<div  id="aaa"  >222222</div>

<button id="btn"> 按钮</button>
<script>


    $('#aaa').attr("class","width:50px")  //相当于 <div  id="aaa"  width="50"  >222222</div>


var num=3;
if(num>0){
     flag='b';
     alert(11)
    $('#aaa').addClass(flag)
}

$('#btn').click(function (){
    alert(222)
    flag='a';
    $('#aaa').addClass(flag)
})


    console.log(document.getElementById('aaa'))
</script>
</body>
</html>